//
//  MoralityViewController.m
//  MXClassroom
//
//  Created by 你个LB on 16/9/8.
//  Copyright © 2016年 你个LB. All rights reserved.
//

#import "MoralityViewController.h"

@interface MoralityViewController ()

@end

@implementation MoralityViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    VOSegmentedControl *segctrl = [[VOSegmentedControl alloc] initWithSegments:@[@{@"text": @"热门大德"},@{@"text": @"汉地大德"},@{@"text": @"得到高僧"},@{@"text": @"藏地大德"}]];
    segctrl.contentStyle = VOContentStyleTextAlone;
    segctrl.indicatorStyle = VOSegCtrlIndicatorStyleBottomLine;
    segctrl.allowNoSelection = NO;
    segctrl.textColor = kColor_text_color;
    segctrl.selectedTextColor = kColor_text_color;
    segctrl.textFont = [UIFont systemFontOfSize:12];
    segctrl.frame = CGRectMake(0, 0, kScreen_width, 40);
    segctrl.selectedTextFont = [UIFont systemFontOfSize:14 weight:2];
    segctrl.indicatorThickness = 0;
    [segctrl addTarget:self action:@selector(segmentCtrlValuechange:) forControlEvents:UIControlEventValueChanged];
    [self.view addSubview:segctrl];
    
    
    [self initDataSource];
    
    [self initTableView];
}

- (void)initDataSource{
    NSMutableArray * models = [NSMutableArray array];
    
    NSArray * data = @[@{@"headImg":@"icon_main_recommend_science_normal.png",
                         @"name":@"南华寺求真大师",
                         @"introduction":@"这是一个次第修学简介"},
                       @{@"headImg":@"icon_main_recommend_science_normal.png",
                         @"name":@"普陀山弘毅",
                         @"introduction":@"菩提本无树，明镜亦非台"},
                       @{@"headImg":@"icon_main_recommend_science_normal.png",
                         @"name":@"五台山大师",
                         @"introduction":@"佛为何物，无色，无味，无我！"},
                       @{@"headImg":@"icon_main_recommend_science_normal.png",
                         @"name":@"无色无我空",
                         @"introduction":@"菩提本无树，明镜亦非台"}];
    
    for (int i = 0; i < 4; i ++) {
        MoralityModel * morality = [[MoralityModel alloc] initWithContentDic:data[i]];
        [models addObject:morality];
    }
    _dataList = models;
}

- (void)initTableView{
    UITableView * tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 40, kScreen_width, kScreen_height - 64 - 48 - 40) style:UITableViewStyleGrouped];
    tableView.dataSource = self;
    tableView.delegate = self;
    [self.view addSubview:tableView];
}

#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataList.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MoralityTableViewCell * cell = [MoralityTableViewCell cellWithTableView:tableView];
    cell.morality = _dataList[indexPath.row];
    return cell;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 0.01;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 70;
    
}
- (void)segmentCtrlValuechange: (VOSegmentedControl *)segmentCtrl{
    NSLog(@"%@: value --> %@",@(segmentCtrl.tag), @(segmentCtrl.selectedSegmentIndex));
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
